package com.mjsoftking.palettelib;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.MotionEvent;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;

/**
 * 用途：基于AppCompatTextView的画板视图，支持任意画线
 * 支持AppCompatTextView 一些特性
 * <p>
 * 作者：MJSoftKing
 */
public class PaletteTextView extends AppCompatTextView {

    public BasePalette palette;

    public PaletteTextView(@NonNull Context context) {
        super(context);
        palette = BasePalette.create(this);
    }

    public PaletteTextView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        palette = BasePalette.create(this);
    }

    public PaletteTextView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        palette = BasePalette.create(this);
    }

    @Override
    @SuppressLint("ClickableViewAccessibility")
    public boolean onTouchEvent(MotionEvent event) {
        return palette.onTouchEvent(event) || super.onTouchEvent(event);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        palette.onDraw(canvas);
    }
}
